package com.example.feidaolumanager.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.example.feidaolumanager.R


/**
 * DialogItemAdapter
 */
class DialogItemAdapter(
    context: Context?, //这里可以传递个对象，用来控制不同的item的效果
    //比如每个item的背景资源，选中样式等
    var list: List<String>?
) :
    BaseAdapter() {
    private var inflater: LayoutInflater

    init {
        inflater = LayoutInflater.from(context)
    }

    override fun getCount(): Int {
        notifyDataSetChanged()
        return list!!.size
    }

    override fun getItem(i: Int): String? {
        return if (i == count || list == null) {
            null
        } else list!![i]
    }

    override fun getItemId(i: Int): Long {
        return i.toLong()
    }

    override fun getView(position: Int, convertView: View?, viewGroup: ViewGroup): View? {

        var holder = ViewHolder()

        var convertView = convertView

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.dialog_item, null)
            convertView.tag = holder
        } else {
            holder = convertView.tag as ViewHolder
        }


        holder.textview!!.text = getItem(position)

        return convertView
    }

    class ViewHolder {
        var textview: TextView? = null
    }
}